package com.xl.studentpass.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xl.studentpass.entity.BaseAreaEntity;
import com.xl.studentpass.entity.SchoolInfoEntity;
import com.xl.studentpass.entity.vo.SchoolVo;
import com.xl.studentpass.mapper.BaseAreaMapper;
import com.xl.studentpass.mapper.SchoolInfoMapper;
import com.xl.studentpass.service.BaseAreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: xl
 * @createTime: 2023/6/5 15:49:58
 * @program: student-pass
 * @e-mail: 2199396150@qq.com
 * @description:
 */
@Service
@Slf4j
@CacheConfig(cacheNames = "area")
public class BaseAreaServiceImpl extends ServiceImpl<BaseAreaMapper, BaseAreaEntity> implements BaseAreaService {
    @Resource
    BaseAreaMapper baseAreaMapper;
    @Resource
    SchoolInfoMapper schoolInfoMapper;

    @Cacheable("city")
    @Override
    public List<BaseAreaEntity> getArea(String area, Integer pageNo, Integer pageSize, Integer provinceId) {
        pageNo = (pageNo - 1) * 10;
        return baseAreaMapper.getArea(area, pageNo, pageSize, provinceId);
    }

    @Cacheable("province")
    @Override
    public List<BaseAreaEntity> getProvince() {
        LambdaQueryWrapper<BaseAreaEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BaseAreaEntity::getParentId, 0);
        return baseAreaMapper.selectList(wrapper);
    }

    @Cacheable("school")
    @Override
    public List<SchoolInfoEntity> getSchools(SchoolVo schoolVo) {
        return schoolInfoMapper.getSchools(schoolVo);
    }

    @Override
    public SchoolInfoEntity getSchoolInfoById(Integer schoolId) {
        return schoolInfoMapper.selectById(schoolId);
    }
}
